#!/usr/bin/env bash

set -e

ASSETS_DIR="assets"
ICONSET_DIR="extra/osx/Neovide.app/Contents/Resources/Neovide.iconset"

mkdir -p "${ICONSET_DIR}"

# make tiff (for dmg background to support retina)

tiffutil \
  -cathidpicheck \
  "${ASSETS_DIR}/neovide-dmg-background.png" \
  "${ASSETS_DIR}/neovide-dmg-background@2x.png" \
  -out "${ASSETS_DIR}/neovide-dmg-background.tiff"

# make icns

sips -z 16 16   "${ASSETS_DIR}/neovide-1024.png" --out "${ICONSET_DIR}/icon_16x16.png"
sips -z 32 32   "${ASSETS_DIR}/neovide-1024.png" --out "${ICONSET_DIR}/icon_16x16@2x.png"
sips -z 32 32   "${ASSETS_DIR}/neovide-1024.png" --out "${ICONSET_DIR}/icon_32x32.png"
sips -z 64 64   "${ASSETS_DIR}/neovide-1024.png" --out "${ICONSET_DIR}/icon_32x32@2x.png"
sips -z 128 128 "${ASSETS_DIR}/neovide-1024.png" --out "${ICONSET_DIR}/icon_128x128.png"
sips -z 256 256 "${ASSETS_DIR}/neovide-1024.png" --out "${ICONSET_DIR}/icon_128x128@2x.png"
sips -z 256 256 "${ASSETS_DIR}/neovide-1024.png" --out "${ICONSET_DIR}/icon_256x256.png"
sips -z 512 512 "${ASSETS_DIR}/neovide-1024.png" --out "${ICONSET_DIR}/icon_256x256@2x.png"
sips -z 512 512 "${ASSETS_DIR}/neovide-1024.png" --out "${ICONSET_DIR}/icon_512x512.png"
cp "${ASSETS_DIR}/neovide-1024.png" "${ICONSET_DIR}/icon_512x512@2x.png"

iconutil -c icns "${ICONSET_DIR}"
rm -R "${ICONSET_DIR}"
